#include "ShapeGenerator.h"
#include "Shape.h"
#include "MyCircle.h"
#include "rectangle.h"
#include<typeinfo>
using namespace std;

Shape* ShapeGenerator::loadShape(ifstream& in_file, bool binary)
{
	ShapeType type;
	if(binary)
		in_file.read( (char*)&type, sizeof(int) );
	else //text
	{
		int tmp;
		in_file >> tmp;
		type = (ShapeType)tmp;
	}

	if( type == RECTANGLE)
			return new MyRectangle(in_file,binary);
	else if( type == CIRCLE)
		return new MyCircle(in_file, binary);
	else //never
		return NULL;
}

ShapeGenerator::ShapeType ShapeGenerator::getType( const Shape *shape)
{
	if( typeid(*shape) == typeid(MyRectangle))
		return RECTANGLE;
	else if( typeid(*shape) == typeid(MyCircle))
		return CIRCLE;
	else
		return UNKNOWN;
}